< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03090406.xhp

(section: function) (bookmark: bm_id3153346)
Function statement

Function ステートメント

Function Statement [Runtime]
Function ステートメント [実行時](hd_id3153346.1)

Defines a subroutine that can be used as an expression to determine a return type.
処理結果を戻り値として返すサブルーチンを定義します。(par_id3159158.2)

(/section: function)

Syntax
構文(hd_id3145316.3)

see Parameter
パラメータを参照(par_id3148944.4)

Parameters:
パラメータ:(hd_id3154760.5)

Syntax
構文(par_id3156344.6)

Function Name[(VarName1 [As Type][, VarName2 [As Type][,...]]]) [As Type]
Function Name[(VarName1 [As Type][, VarName2 [As Type][,...]]])[As Type](par_id3149457.7)

statement block
ステートメントブロック(par_id3153360.8)

[Exit Function]
[Exit Function](par_id3148797.9)

statement block
ステートメントブロック(par_id3145419.10)

End Function
End Function(par_id3150449.11)

Parameter
パラメータ(par_id3156281.12)

Name: Name of the subroutine to contain the value returned by the function.
Name: 関数が返す値を格納しておくサブルーチン名。(par_id3153193.13)

VarName: Parameter to be passed to the subroutine.
VarName: サブルーチンに渡すパラメータ。(par_id3147229.14)

Type: Type-declaration keyword.
Type: 型宣言用のキーワード。(par_id3147287.15)

Example:
例:(hd_id3163710.16)

Sub ExampleExit
Sub ExampleExit(par_id3147214.17)

Dim sReturn As String
Dim sReturn As String(par_id3152596.18)

Dim sListArray(10) as String
Dim sListArray(10) as String(par_id3153364.19)

Dim siStep as Single
Dim siStep as Single(par_id3149481.20)

For siStep = 0 to 10 REM Fill array with test data
For siStep = 0 to 10 REM 配列にテスト用データを代入(par_id3152939.21)

sListArray(siStep) = chr$(siStep + 65)
sListArray(siStep) = chr$(siStep + 65)(par_id3147349.22)

msgbox sListArray(siStep)
msgbox sListArray(siStep)(par_id3147426.23)

next siStep
Next siStep(par_id3152576.24)

sReturn = LinSearch(sListArray(), "B")
sReturn = LinSearch(sListArray(), "B")(par_id3146922.25)

Print sReturn
Print sReturn(par_id3153140.26)

end sub
end sub(par_id3149581.27)

Function LinSearch( sList(), sItem As String ) as integer
Function LinSearch( sList(), sItem As String ) as integer(par_id3154790.30)

dim iCount as Integer
dim iCount as Integer(par_id3150594.31)

REM Linsearch searches a TextArray:sList() for a TextEntry:
REM LinSearch はテキスト配列 sList( ) 内に指定文字列を検索(par_id3154943.32)

REM Return value is the index of the entry or 0 (Null)
REM 戻り値は、該当するインデックス値ないしゼロ (Null)(par_id3155601.33)

for iCount=1 to Ubound( sList() )
for iCount=1 to Ubound( sList() )(par_id3154511.34)

if sList( iCount ) = sItem then
if sList( iCount ) = sItem then(par_id3149123.35)

exit for REM sItem found
exit for REM 検索で sItem がヒット(par_id3153707.36)

end if
end if(par_id3155066.37)

next iCount
Next iCount(par_id3156275.38)

if iCount = Ubound( sList() ) then iCount = 0
if iCount = Ubound( sList() ) then iCount = 0(par_id3156054.39)

LinSearch = iCount
LinSearch = iCount(par_id3153765.40)

end function
end function(par_id3153713.41)


< Prev / Next >